%Gaussian pyramid
%Each next level of the Gaussian pyramid is the downsampled version of the
%previous level. A 5-tap gaussian low lass filter is used prior to
%downsampling (implemented in resample2D function)
%Arguments: image I, its height and width

%This function was written after studying T. Mertens', J. Kautz' and 
%F. Van Reeth's implementation of Exposure Fusion
%http://research.edm.uhasselt.be/~tmertens/exposure_fusion/

function pyramid = gauss_pyramid(I,rows,cols) 

%we find total number of levels by calculating how many times the
%smallest dimension can be divided by 2 (until result of the iteration
%becomes less than 1):
numL = floor(log2(min(rows,cols)));

pyramid = cell(numL,1); %use a vertical cell array to store levels
pyramid{1} = I;         %Image itself is a first level of the pyramid

for j = 2:numL          %starting at the second level
    %downsample the signal
    I = resample2D(I,'down');
    pyramid{j} = I;
end





    
